package ishacrm.client;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.user.client.ui.HTMLPanel;

public class ViewImplFactory {
	
	private static Map<String, HTMLPanel> cache = new HashMap<String, HTMLPanel>();		
	
	static HTMLPanel get(String token) {
		if (token == null)
			return getUndefinedViewImpl("token is null");
		
		if (token.equals(""))
			token = "checkin";
		
		token = token.toLowerCase();
		if (token.contains("checkin"))
			return getCheckinViewImpl();
		
		return getUndefinedViewImpl("invalid token [" + token + "]");
	}
	
	static HTMLPanel getUndefinedViewImpl(String message) {		
		HTMLPanel htmlPanel = new HTMLPanel("Undefined view - " + message);	
		return htmlPanel;
	}
	
	static HTMLPanel getCheckinViewImpl() {
		
		if (cache.containsKey("checkin"))
			return cache.get("checkin");
				
		HTMLPanel htmlPanel = new HTMLPanel("");		
		Checkin checkin = new Checkin();
		htmlPanel.add(checkin);
		cache.put("checkin", htmlPanel);
		
		return htmlPanel;
	}
}
